using System;
using System.Collections.Generic;
using System.Text;
using BuildingBasicDomain;
using CommonTypes.Math;

namespace BuildingStructuralElements
{
    public class ModificationWorkBench : ILinearModifications
    {

        /// <summary>
        /// Method splitLine
        /// </summary>
        /// <returns>A bool</returns>
        /// <param name="line2">An ILine</param>
        public bool splitLine(ILine line)
        {
            // TODO: Implement this method
            return false;
        }

        /// <summary>
        /// Method joinline
        /// </summary>
        /// <returns>A bool</returns>
        /// <param name="line2">An ILine</param>
        public bool joinline(ILine line)
        {
            // TODO: Implement this method
            return false;
        }

        /// <summary>
        /// Method joinline
        /// </summary>
        /// <returns>A bool</returns>
        /// <param name="point">An IPoint</param>
        public bool joinline(IPoint point)
        {
            // TODO: Implement this method
            return false;
        }

        public bool extendLine(IPoint point, ref INodeLine line)
        {

            if (!line.ContainsPointOpen(point))
            {
                Vector3D v1 = line.SNode.V - point.V;
                Node node = new Node(point.X, point.Y, point.Z);

                if (node.distancePoint(line.SNode) > node.distancePoint(line.ENode))
                {
                    line.Add(line.ENode as Node);
                    line.ENode = node;
                }
                else
                {
                    line.Add(line.SNode as Node);
                    line.SNode = node;
                }

                return true;
            }
            return false;
        }
        public bool extendLine(ILine line, ref INodeLine extendedline)
        {
            IPoint point = extendedline.IntersectsLine(line, CommonTypes.Geometry.Type_of_Intersection .On_SomethingMine_I_Realy_do_Not_remenber_in_this_fucking_mess );
            return extendLine(point, ref extendedline);
        }
        public bool extendLine(IPlane plane, ref INodeLine line)
        {
            IPoint point = line.IntersectsPlane(plane);
            extendLine(point, ref line);
            return false;
        }

        public bool trimLine(IPoint point, ref INodeLine line)
        {
            if (line.ContainsPointOpen(point))
            {

                line.ENode = new Node(point.X, point.Y, point.Z);
                return true;

            }
            return false;

        }
        public bool trimLine(ILine line, ref INodeLine extendedline)
        {
            IPoint point = extendedline.IntersectsLine(line, CommonTypes.Geometry.Type_of_Intersection .On_SomethingMine_I_Realy_do_Not_remenber_in_this_fucking_mess );
            return trimLine(point, ref extendedline);
        }
        public bool trimLine(IPlane plane, ref INodeLine line)
        {
            IPoint point = line.IntersectsPlane(plane);
            return trimLine(point, ref line);
        }

        public bool splitLine(int divisions) { return false; }
        public bool splitLine(IPoint point)
        {
            return false;
        }

    }

    public interface ILinearModifications
    {

        bool extendLine(IPoint point, ref INodeLine line);
        bool extendLine(ILine line, ref INodeLine extenedline);
        bool extendLine(IPlane plane, ref INodeLine line);

        bool trimLine(IPoint point, ref INodeLine line);
        bool trimLine(ILine line, ref INodeLine extenedline);
        bool trimLine(IPlane plane, ref INodeLine line);

        bool splitLine(int divisions);
        bool splitLine(IPoint point);
        bool splitLine(ILine line);

        bool joinline(ILine line);
        bool joinline(IPoint point);
    }
}
